package cn.hinglo.common.timer;

import cn.hinglo.permission.model.Jdk;
import cn.hutool.core.util.NetUtil;
import cn.hutool.system.RuntimeInfo;
import cn.hutool.system.SystemUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;

import java.util.Date;

/***
 * Jdk 虚拟机信息定时任务采集器
 * @author HingLo
 */
public class JdkMonitorJob implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        RuntimeInfo runtimeInfo = SystemUtil.getRuntimeInfo();
        Jdk jdk = new Jdk().setDate(new Date())
                .setTotal(runtimeInfo.getTotalMemory())
                .setUse(runtimeInfo.getUsableMemory())
                .setFree(runtimeInfo.getFreeMemory())
                .setMax(runtimeInfo.getMaxMemory())
                .setIp(NetUtil.getLocalhostStr());
        jdk.save();
    }
}
